package com.wpp.mq.rabbitmqsqmple.democase;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @description:
 * @author: WangPengPeng
 * @create: 2021-11-28 16:01
 **/
public class SendDemo1 {

    private static String QUEUE_NAME = "hello3";

    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.86.128");
        factory.setVirtualHost("/");
        factory.setUsername("root");
        factory.setPassword("root");
        factory.setPort(5672);
        try {
            Connection conn = factory.newConnection();
            Channel channel = conn.createChannel();
            ((Channel) channel).queueDeclare(QUEUE_NAME, false, false, true, null);
            String message = "Hello World!";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");

        } catch (Exception e) {
        }
    }
}
